.MODEL SMALL
.STACK 64
.DATA


		SANGRIA		EQU		24
		LEFTLIM		EQU		00
		RIGHTLIM	EQU		29
		NOCHARS		EQU		30
		COL			DB		00
		ROW			DB		10
		COLT		DB		?
		CONT1		DB		?
		DATASTR		DB		'               '
					DB		'               ',20H
		.386	

.CODE
A10MAIN		PROC	FAR
			MOV 	AX, @data
			MOV 	DS, AX
			MOV 	ES, AX
			CALL	Q10CLEAR
			CALL	Q20CURSOR
			CALL 	Q30DISPLAY
			
A30:
			CALL	Q20CURSOR
			CALL 	B10KEYBOARD
			CMP 	AH, 01H
			JNE		A30
			MOV 	AX, 0600H
			CALL	Q10CLEAR 
			MOV		AX, 4C00H
			INT 	21H
A10MAIN		ENDP


B10KEYBOARD	PROC	NEAR
			MOV		AH, 10H
			INT		16H
			CMP		AL, 00H
			JE		B20
			CMP		AL, 08H
			JE		B10
			CMP		AL, 09H
			JE		B70
			CMP		AL, 0E0H
			JE		B20
			CALL	H10CHARS
			JMP		B90
B10:
			CALL	E10DELETE
			JMP		B90	
B20:
			CMP 	AH, 4DH
			JNE		B30
			CALL	C10RTARRW
			JMP		B90
B30:
			CMP		AH, 4BH
			JNE		B50
			CALL	D10LFARRW
			JMP		B90
B50:
			CMP		AH, 47H	
			JNE		B60
			CALL	F10HOME
			JMP		B90
B60:			
			CMP		AH, 4FH
			JNE		B90
			CALL 	G10END
			JMP		B90
B70:
			CALL	EDITORTAB 
			JMP		B90			
B90:
			RET
B10KEYBOARD	ENDP		


C10RTARRW	PROC	NEAR
			CMP		COL, RIGHTLIM
			JAE		C20
			INC		COL
			JMP		C90
C20:
			CALL	F10HOME
C90:
			RET
C10RTARRW	ENDP


D10LFARRW	PROC	NEAR
			CMP		COL, LEFTLIM
			JBE		D20
			DEC		COL
			JMP		D90
D20:
			CALL	G10END
D90:
			RET
D10LFARRW	ENDP


EDITORTAB	PROC	NEAR
			ADD		COL, 5
			ADD		CONT1, 5
			CALL	Q20CURSOR
			RET
EDITORTAB	ENDP		


E10DELETE	PROC	NEAR
			CMP		COL, LEFTLIM
			JE		E13
			CMP		COL, RIGHTLIM
			JE		E11
			CMP		COL, LEFTLIM+1
			JE		E12
			MOVZX	BX, COL
			MOV		DATASTR[BX-1], 20H
E5:			
			MOV		COLT, BL
			SUB		COLT, 1
E6:
			MOV		BL, COLT
			MOV		COL, BL
			CALL	Q20CURSOR
			MOV		AL, 20H
			CALL	Q40DISCHR
			MOV		COL, BL
			CALL	Q20CURSOR
			DEC		CONT1
			JMP		E13
E11:
			MOV		COL, RIGHTLIM
			MOV		AL, 20H
			CALL	Q40DISCHR
			MOV		BX, RIGHTLIM
			MOV		DATASTR[RIGHTLIM], 20H
			JMP		E5
E12:		
			MOV		COL, LEFTLIM
			MOV		AL, 20H
			CALL	Q40DISCHR
			MOV		COL, LEFTLIM
			CALL	Q20CURSOR
			MOV		AL, 20H
			CALL	Q40DISCHR
			MOV		BX, LEFTLIM
			MOV		DATASTR[LEFTLIM], 20H
			DEC		CONT1
E13:			
			RET
E10DELETE	ENDP


F10HOME		PROC	NEAR
			;MOV		CONT1, 
			MOV		COL, LEFTLIM
			CALL	Q20CURSOR
			RET
F10HOME		ENDP


G10END		PROC	NEAR
			;SUB		CONT1, 1
			MOV		BL, CONT1
			MOV		COL, BL
			CALL	Q20CURSOR
			RET
G10END		ENDP			


H10CHARS	PROC	NEAR
			CMP		AL, 20H
			JB		H90
			CMP		AL, 7EH
			JA		H90
			MOVZX	BX, COL
			LEA		DI, DATASTR
			MOV		[DI+BX], AL
			CALL	Q40DISCHR
			CMP		COL, RIGHTLIM
			JAE		H90
			INC		COL
			INC		CONT1
H90:
			RET
H10CHARS	ENDP


Q10CLEAR	PROC	NEAR
			MOV		AX, 0600H
			MOV		BH, 61H
			MOV		CX, 0000
			MOV 	DX, 184FH
			INT		10H
			RET
Q10CLEAR	ENDP


Q20CURSOR	PROC	NEAR
			MOV		AH, 02H
			MOV		BH, 00
			MOV		DH, ROW
			MOV 	DL, COL
			ADD		DL, SANGRIA
			INT		10H
			RET
Q20CURSOR	ENDP


Q30DISPLAY	PROC	NEAR
			MOV		AX, 1301H
			MOV		BX, 0016H
			LEA		BP, DATASTR
			MOV		CX, NOCHARS+1
			MOV		DH, ROW
			MOV		DL, COL
			MOV		DL, SANGRIA
			INT 	10H
			RET
Q30DISPLAY	ENDP


Q40DISCHR	PROC	NEAR
			MOV		AH, 0AH
			MOV		BH, 00
			MOV		CX, 01
			INT 	10H
			RET
Q40DISCHR	ENDP
			END		A10MAIN
			
			


	
			
			
			